%TVR
%Total variation regularization method was implemented here to reconstruct
%the image x0. X0 is the referrence. 

%initial guess of x0. set to 0
x0 = single(zeros(size(X0)));

%total iterations used 
totalIter = 200;
x_recon = x0;

%the iteration steps used in the second parts
GDIter = 20;

%parameter sets 
lamda = single([1,0.1,0.05,0.01,0.005,0.0001,0.00005,0.000001]);

%
for testiter= 1:length(lamda)
  [x_recon, l2error, uqierror,ssimerror,corr2error,time] = TVR(para,prjimg,totalIter,x0,GDIter,lamda(testiter),X0);
  
  %save
  filename = sprintf('results/tvr_gditer_%d',testiter);
  save(filename,'x_recon', 'l2error', 'uqierror','ssimerror','corr2error','time','lamda','para');
  
  %show results
  figure;imagesc(reshape(x_recon,para.nx,para.nx));colormap('gray');drawnow;
  figure;plot(l2error);colormap('gray');drawnow;
  
  
end